package bank;

import java.util.ArrayList;

import branch_access.*;

import mware_lib.NameService;

/**
 * Manager:
 * our implementation of the abstract manager class.
 * The Manager can create and delete Accounts.
 * @author Rico Flaegel
 * @author Jan Quenzel
 */
public class Manager_Impl extends Manager{
	/**
	 * List of associated accounts
	 */
	ArrayList<Account_Impl> accountList;
	/**
	 * @uml.property  name="ns"
	 * @uml.associationEnd  
	 */
	NameService ns;
	static long listnr = 0;
	
	public Manager_Impl(NameService ns) {
		accountList = new ArrayList<Account_Impl>();
		this.ns = ns;
	}

	@Override
	public String createAccount(String owner) {
		Account_Impl acc = new Account_Impl(owner);
		accountList.add(acc);
		ns.rebind(acc, acc.accountID);
		return acc.accountID;
	}

	@Override
	public boolean removeAccount(String accountID) {
		for (Account_Impl elem : accountList) {
			System.out.println(elem.accountID + " - " + accountID);
			if(elem.accountID.equals(accountID)){
				accountList.remove(elem);
				return true;
			}
		}
		return false;
	}

}
